package sctu.edu.java.year2016.team01.xuhanmei.day20160605.chapter12_2;

import java.io.*;
import java.util.Arrays;

/**
 * Created by Administrator on 2016/6/5.
 * 使用字符输入、输出流读取文件，将一段文字加密后存入文件，在后再读取，并将加密前的文件与
 * 加密后的文件输出。。
 * 未完成！！
 */
public class FileReaderandSecret {
    public static void main(String[] args) throws IOException {

        FileReader fr = null;
        // FileWriter fw=null;
        FileOutputStream fo=null;

        try {

            fr = new FileReader("d:/java小程序/12_2.txt");
              fo=new FileOutputStream("d:/java小程序/12_2.txt");

            char[] c = new char[100];
            fr.read(c, 0, c.length);
            System.out.println("12_2.txt里的内容是：");
            for (int i = 0; i < c.length; i++) {
                System.out.print(c[i]);
            }
            System.out.println();


            String s = "abcde";
            //  char[] c1=new char[2000];

            //      fw.write(c,0,temp);
            //      fw.write(s, 0, s.length());

            byte[] a=new byte[10000];
            fo.write(a,0,a.length);
            System.out.println();
            System.out.println("加密前的字符为：");
            System.out.print(s + "\n");
            System.out.println();




            byte[] b = s.getBytes();
            System.out.println("加密后的字符为：");
            for (int i = 0; i < s.length(); i++) {
                b[i] = (byte) (b[i] ^ 5);
                System.out.print(b[i] + "\t");
            }
            System.out.println("\n将加密后的字符写入b：");
            fo.write(b, 0, b.length);
            System.out.print(b);


        } catch (FileNotFoundException e1) {
            e1.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


}
